//
//  ORErrorView.m
//  NewsWith
//
//  Created by rimi on 2016/12/17.
//  Copyright © 2016年 dongfumei. All rights reserved.
//

#import "ORErrorView.h"

@implementation ORErrorView

+(instancetype)sharedError{
    static ORErrorView *errorView = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        errorView = [[ORErrorView alloc] initWithFrame:AAdaptionRect(0, 64, kBaseWidth, 44)];
        errorView.backgroundColor = [UIColor yellowColor];
        errorView.alpha = 0;
    });
    return errorView;
}

-(void)showAnimaction{
    [self showRoundProgressWithTitle:@"加载中..."];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self showRightWithTitle:@"加载成功" autoCloseTime:1];
    });
}



- (void)showErrorWithTitle:(NSString *)title {
    self.errorLabel.text = title;
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    } completion:^(BOOL finished) {
        [self hideAnimation];
    }];
}

- (void)hideAnimation {
    [UIView animateWithDuration:0.3 delay:0.5 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(UILabel *)errorLabel{
    if (!_errorLabel) {
        _errorLabel = [[UILabel alloc]initWithFrame:AAdaptionRect(0, 0, kBaseWidth, 44)];
        _errorLabel.textAlignment = NSTextAlignmentCenter;
        
    }
    return _errorLabel;
}


@end
